<template>
  <!-- <div class="xtx-checkbox" @click="changeChecked()"> -->
  <div class="xtx-checkbox" @click="checked = !checked">
    <i v-if="checked" class="iconfont icon-checked"></i>
    <i v-else class="iconfont icon-unchecked"></i>
    <span v-if="$slots.default"><slot /></span>
  </div>
</template>
<script>
import { useVModel } from '@vueuse/core'
// import { toRef } from 'vue'
export default {
  name: 'XtxCheckbox',
  props: {
    modelValue: {
      type: Boolean,
      default: false
    }
  },
  setup(props, { emit }) {
    // 方法一 通过 toRef方法 来实现 数据的双向绑定
    /*  const checked = toRef(props, 'modelValue')
    const changeChecked = () => {
      emit('update:moudleValue', !checked.value)
    }
    return { checked, changeChecked } */
    const checked = useVModel(props, 'modelValue', emit)
    return { checked }
  }
}
</script>
<style scoped lang="less">
.xtx-checkbox {
  display: inline-block;
  margin-right: 2px;
  .icon-checked {
    color: @xtxColor;
    ~ span {
      color: @xtxColor;
    }
  }
  i {
    position: relative;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}
</style>
